package com.tanhua.admin.mapper;

import cn.hutool.core.date.DateTime;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.tanhua.model.admin.Analysis;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.Date;

import java.util.List;

@Mapper
public interface AnalysisMapper extends BaseMapper<Analysis> {

    @Select("select sum(num_registered) from tb_analysis_by_day")
    Integer queryCumulativeUsers();

    //查询30天以内活跃用户
    @Select("SELECT SUM(num_active) FROM tb_analysis_by_day WHERE DATE_SUB(CURDATE(), INTERVAL 30 DAY) <= DATE(record_date) ")
    Integer queryThiryDaysUser();

    //查询七天以内活跃用户
    @Select("SELECT SUM(num_active) FROM tb_analysis_by_day WHERE DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= DATE(record_date)")
    Integer querySevenDaysUser();

    //查询今日活跃用户
    @Select("select SUM(num_active) from tb_analysis_by_day where year(record_date)=year(now()) and month(record_date)=month(now()) and day(record_date)=day(now())")
    Integer queryTodayActive();

    //查询今日登录用户
    @Select("select SUM(num_login) from tb_analysis_by_day where year(record_date)=year(now()) and month(record_date)=month(now()) and day(record_date)=day(now())")
    Integer queryTodayLogin();

    //查询今日之前新增用户
    @Select("SELECT SUM(num_registered) FROM tb_analysis_by_day  WHERE record_date< CURDATE()")
    Integer queryTodayRegistered();

    //查询全部注册用户
    @Select("SELECT SUM(num_registered) FROM tb_analysis_by_day")
    Integer queryRegistered();

//    @Select("SELECT record_date AS title,${type} AS amout FROM tb_analysis_by_day WHERE record_date BETWEEN #{start} AND #{end} GROUP by title")
//    List<Object> queryThisYear(@Param("start") String sdTime, @Param("end") String edTime, @Param("type") Integer type);
//
//    @Select("SELECT record_date AS title,${type} AS amout FROM tb_analysis_by_day WHERE record_date BETWEEN SUBDATE(#{start},INTERVAL 1 YEAR ) AND SUBDATE(#{end},INTERVAL 1 YEAR ) GROUP by title")
//    List<Object> queryLastYear(@Param("start") String sdTime, @Param("end") String edTime, @Param("type") Integer type);
}
